package com.android.qjpmc.application_module.station.fragment;

import android.text.TextUtils;
import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.android.qjpmc.R;
import com.android.qjpmc.application_module.contract.StationVideoFragmentContract;
import com.android.qjpmc.application_module.home.viewModel.HomeViewModel;
import com.android.qjpmc.application_module.viewModel.StationVideoFragmentViewModel;
import com.android.qjpmc.bean.StationDataBean;
import com.android.qjpmc.bean.StationVideoListBean;
import com.android.qjpmc.databinding.FragmentStationVideoBinding;
import com.android.qjpmc.manager.IntentManager;
import com.android.qjpmc.widget.databindingadapter.BaseBindingItemPresenter;
import com.android.qjpmc.widget.databindingadapter.SingleTypeBindingAdapter;
import com.android.qjpmc.widget.mvvm.factory.CreateViewModel;
import com.android.qjpmc.widget.mvvm.view.BaseMVVMFragment;
import com.android.qjpmc.widget.utils.ToastUtils;

import java.util.List;

@CreateViewModel(StationVideoFragmentViewModel.class)
public class StationVideoFragment extends BaseMVVMFragment<StationVideoFragmentViewModel, FragmentStationVideoBinding> implements StationVideoFragmentContract.View, BaseBindingItemPresenter<StationVideoListBean> {
    @Override
    public int getLayoutId() {
        return R.layout.fragment_station_video;
    }

    @Override
    public void initView() {

    }

    @Override
    public void initData() {
        mViewModel.getVideoListOfStation(stationData, stationId);
    }

    @Override
    public void initEvent() {

    }

    private StationDataBean stationData;
    private String stationId;

    public void initStationData(String stationId, StationDataBean data) {
        this.stationData = data;
        this.stationId = stationId;
    }

    @Override
    public void returnVideoList(List<StationVideoListBean> videoListBeanList) {
        SingleTypeBindingAdapter adapter = new SingleTypeBindingAdapter(mActivity, videoListBeanList, R.layout.item_station_video);
        mBinding.recyclerView.setAdapter(adapter);
        adapter.setItemPresenter(this);
        mBinding.recyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
    }

    @Override
    public void onItemClick(int position, StationVideoListBean itemData) {
        if (TextUtils.isEmpty(itemData.url)) {
            ToastUtils.showShort("视频流为null,请配置数据");
            return;
        }
        IntentManager.toVideoActivity(mActivity, itemData);

    }
}
